package servlet;

import dao.BoardDao;
import dao.ReplyDao;
import dao.UserDao;
import dao.impl.BoardDaoImpl;
import dao.impl.ReplyDaoImpl;
import dao.impl.UserDaoImpl;
import entity.Board;
import entity.Topic;
import entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.nio.file.FileStore;
import java.util.List;

@WebServlet(name = "DeleteReplyServlet",urlPatterns = "/DeleteReplyServlet")
public class DeleteReplyServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        ReplyDao replyDao = new ReplyDaoImpl();

        String page = request.getParameter("page");
        String replyID = request.getParameter("replyID");
        String boardID = request.getParameter("boardID");
        String topicID = request.getParameter("topicID");
        int uid = replyDao.finduidReply(Integer.parseInt(replyID));
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");
        if(user!=null&&user.getUId()==uid){
            replyDao.deleteReply(Integer.parseInt(replyID));
            System.out.println("删除成功!");
            response.sendRedirect("detail.jsp?page="+page+"&boardID="+boardID+"&topicID="+topicID);

        }else{
            request.getRequestDispatcher("detail.jsp?page="+page+"&boardID="+boardID+"&topicID="+topicID).forward(request, response);

        }




    }
}
